package com.example.othree.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.othree.entity.Drone2;
import com.example.othree.entity.FlightDataCount;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Mapper
public interface Drone2Mapper extends BaseMapper<Drone2> {

//    IPage PageList(IPage<Drone2> page, @Param(Constants.WRAPPER) Wrapper wrapper);
    @Select("SELECT * FROM drone_observation_data2 ${ew.customSqlSegment}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "equipment_name",property = "equipmentName"),
            @Result(column = "equipment_number",property = "equipmentNumber"),
            @Result(column = "detection_date",property = "detectionDate"),
            @Result(column = "temp",property = "temp"),
            @Result(column = "PM1_0",property = "pm100"),
            @Result(column = "PM2_5",property = "pm25"),
            @Result(column = "PM10",property = "pm10"),
            @Result(column = "humidity",property = "humidity"),
            @Result(column = "o3",property = "o3"),
            @Result(column = "start_time",property = "startTime"),
            @Result(column = "end_time",property = "endTime"),
            @Result(column = "times",property = "times"),
            @Result(column = "direction",property = "direction"),
            @Result(column = "height",property = "height"),
            @Result(column = "city",property = "city")
    })
    IPage<Drone2> PageList(IPage<Drone2> page, @Param(Constants.WRAPPER) Wrapper<Drone2> wrapper);

    ArrayList<Drone2> getDataById(Integer id);

    // 自定义查询，查询equipmentName和对应的日期，以及每个日期的飞行次数
    @Select("SELECT DISTINCT DATE_FORMAT(CONVERT_TZ(detection_date, '+00:00', '+08:00'), '%Y-%m-%d') AS detection_date, " +
            "COUNT(DISTINCT times) AS flight_count " +
            "FROM drone_observation_data2 " +
            "WHERE equipment_name = #{equipmentName} " +
            "GROUP BY detection_date")
    List<FlightDataCount> selectFlightCountByEquipmentName(String equipmentName);


    List<Drone2> selectByCondition(String equipmentName, String detectionDate, Integer times);

}
